<?php
namespace app\shop\controller;
use app\admin\controller\Admin;
use app\AdminRest;
use app\shop\model\BargainConfig;
use app\shop\model\Express;
use think\App;
use think\facade\Db;
use think\Request;
use app\shop\model\AdminShopSetting as ShopSettingModel;
class AdminShopSetting extends AdminRest
{

    protected $model;
    public function __construct(App $app) {
        parent::__construct($app);
        $this->model = new ShopSettingModel();
    }

    /**
     * 获取商城配置
     */
    public function configInfo(){
        $dis['uniacid'] = $this->_uniacid;
        $data = $this->model->configInfo($dis);
        return $this->success($data);
    }

    /**
     *
     * 修改商城配置
     */

    public function configUpdate(){
        $dis['uniacid'] = $this->_uniacid;
        $data = $this->_input;
        $res  = $this->model->configUpdate($dis,$data);
        if(!empty($res))longbingGetAppConfig($this->_uniacid ,true);
        return $this->success($res);
    }
    /**
     *
     * 添加|修改支付配置
     */
    
    public function configPay(){
        $input = $this->_input;
        $data  = Db::name('longbing_card_config_pay')->where(['uniacid'=>$this->_uniacid])->find();
        if(empty($data)){
            Db::name('longbing_card_config_pay')->insert(['uniacid'=>$this->_uniacid,'create_time'=>time()]);
            $data = Db::name('longbing_card_config_pay')->where(['uniacid'=>$this->_uniacid])->find();
        }
        if(count($input)>1){
            if(!strstr($input['cert_path'],FILE_UPLOAD_PATH)){
                $input['cert_path'] = FILE_UPLOAD_PATH.$input['cert_path'];
            }
            if(!strstr($input['key_path'],FILE_UPLOAD_PATH)){
                $input['key_path']  = FILE_UPLOAD_PATH.$input['key_path'];
            }
            $input['update_time'] = time();
            Db::name('longbing_card_config_pay')->where(['uniacid'=>$this->_uniacid])->update($input);
        }
        return $this->success($data);
    }


    /**
     * @author chenniang
     * @DataTime: 2021-04-12 16:16
     * @功能说明:快递配置详情
     */
    public function expressInfo(){

        $dis = [

            'uniacid' => $this->_uniacid
        ];

        $express_model = new Express();

        $data = $express_model->dataInfo($dis);

        return $this->success($data);


    }


    /**
     * @author chenniang
     * @DataTime: 2021-04-12 16:17
     * @功能说明:快递配置编辑
     */
    public function expressUpdate(){

        $input = $this->_input;

        $dis = [

            'uniacid' => $this->_uniacid
        ];

        $express_model = new Express();

        $data = $express_model->dataUpdate($dis,$input);

        return $this->success($data);


    }


    /**
     * @author chenniang
     * @DataTime: 2021-08-04 17:01
     * @功能说明:分享设置详情
     */
    public function shareInfo(){

        $input = $this->_param;

        $dis = [

            'uniacid' => $this->_uniacid
        ];

        $model = new BargainConfig();

        $data = $model->dataInfo($dis);

        return $this->success($data);
    }


    /**
     * @author chenniang
     * @DataTime: 2021-08-04 17:02
     * @功能说明:分享设置编辑
     */
    public function shareUpdate(){

        $input = $this->_input;

        $dis = [

            'uniacid' => $this->_uniacid
        ];

        $model = new BargainConfig();

        $data = $model->dataUpdate($dis,$input);

        return $this->success($data);

    }





}
